package com.bird.user.remote

import cn.dev33.satoken.annotation.SaIgnore
import com.bird.component.lang.common.response.JSONResponse
import com.bird.component.lang.common.response.success
import com.bird.component.lang.util.log
import com.bird.component.lang.util.paramcheck.toCheck
import com.bird.user.application.UserCommandService
import com.bird.user.application.UserQueryService
import com.bird.user.application.pl.*
import org.springframework.web.bind.annotation.*

/**
 * 用户控制器
 */
@RestController
@RequestMapping("/user")
class UserController(private val userCommandService:UserCommandService,
                     private val userQueryService:UserQueryService
) {
    /**
     * 用户注册
     */
    @SaIgnore
    @PostMapping("/register")
    fun register(@RequestBody userRegisterRequest: UserRegisterRequest):JSONResponse<Unit> {
        log.info("用户注册入参：$userRegisterRequest")
        toCheck {
            notEmpty("用户名", userRegisterRequest.username)
            notEmpty("密码", userRegisterRequest.password)
        }
        userCommandService.register(userRegisterRequest)
        return success()
    }

    /**
     * 获取当前用户信息
     */
    @GetMapping("/me")
    fun me():JSONResponse<MeResponse> {
        log.info("获取当前用户信息")
        return success {
            userQueryService.me()
        }
    }


}